﻿// -----------------------------------------------------------------------
// <copyright file="UpdateUserNameCommandHandler.cs">
// Copyright (c) 2013 Andrey Veselov. All rights reserved.
// License:  Microsoft Public License (MS-PL)
// Contacts: http://andrey.moveax.com  andrey@moveax.com
// </copyright>
// -----------------------------------------------------------------------

namespace Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.DataAccess.CommandHandlers.Users
{
	using System.Diagnostics.Contracts;
	using Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.DataAccess.Database.Dto;
	using Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.Model.Commands.Users;

	internal class UpdateUserNameCommandHandler : ICommandHandlerSync<UpdateUserNameCommand>
	{
		private readonly IRepository _repository;

		public UpdateUserNameCommandHandler(IRepository repository)
		{
			Contract.Requires(repository != null);

			this._repository = repository;
		}

		public void Execute(UpdateUserNameCommand command)
		{
			var userProfile = new UserDto() {
				Id = command.Id,
				Name = command.Name,

				// Following fields are required by EF validation engine, but should be ignored on update.
				Email = "fake@email.com"
			};

			this._repository.UpdateSpecifiedProperties(userProfile, p => p.Name);
		}
	}
}